<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>企业用户管理</title>
 <link rel="styleSheet" href="../../css/bootstrap.min.css"> 
<style type="text/css">
#div {
	margin-left: 100px;
	margin-top:50px;
}
#table{
	width: 900px;
}
#tablediv {
	width: 900px;
	height: 100px;
}
#yediv{
	padding-top: 50px;
}

#but{
	margin-top:80px;
	margin-left: 150px;
}
td{
	text-align: center;
}

#p1 {
	margin-left: 110px;
}
#sel{
	margin-left: 50px;
	height: 30px;
}
#kong{
	width: 50px;
}
#kong1 {
	width: 150px;
}

</style>
</head>
<body>
	<br>
	<br>
	<div id="div">
		<select class="btn btn-default" id="sel">
			<option value="1">企业名称</option>
			<option value="2">企业联系人</option>
			<option value="3">联系电话</option>
		</select> <label id="kong"></label> 
		<input type="hidden" id="hidden" value="">
		<input id="name" type="text">
		&nbsp;&nbsp;&nbsp;&nbsp; 
		<input id="chabut" type="button" class="btn btn-primary" value="查询">
		<label id="kong1"></label>
		<a href="addEnterprise.jsp" class="btn btn-success">新增企业</a> 
			<br> <br>
		<div id="tablediv">
			<table id="table" class="table table-striped table-bordered">
				<tr>
					<td>编号</td>
					<td>企业名称</td>
					<td>企业楼层</td>
					<td>企业联系人</td>
					<td>联系电话</td>
					<td>删除企业</td>
				</tr>
			</table>
			
		</div>
		<div id="yediv">
			<p class="fen" id="but">
					<a class="btn btn-primary">首页</a>
					 &nbsp;&nbsp; 
					 <a class="btn btn-info">上一页</a> &nbsp; 
					 <span id="curPage">1</span>/<span id="countPage"></span> &nbsp; 
					 <a class="btn btn-success">下一页</a>
					&nbsp;&nbsp; 
					<a class="btn btn-warning">末页</a>
			</p>
		</div>
	</div>
	<script type="text/javascript" src="../../js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
		function fenye(page, name) {
			var zhi = $("#sel").val();
			$.ajax({
				type : "POST",
				url : "../../findAllEnterprise.do",
				data : {
					"page" : page,
					"name" : name,
					"zhi" : zhi
				},
				async: false,
				success : function(emps) {
					
					var msg = emps.list;
					var table;
					for (var i = 0; i < msg.length; i++) {
						table = table + "<tr><input  type='hidden' value="+msg[i][0]+"><td>" + (i + 1) + "</td><td>"
								+ msg[i][1] + "</td><td>" + msg[i][2]
								+ "</td><td>" + msg[i][3] + "</td><td>"
								+ msg[i][4] + "</td><td><input onclick='delete1("+msg[i][0]+")' type='button' class='btn btn-danger' value='删除企业'></td></tr>";
					}
					 $("#table").append(table);
					 $("#countPage").html(emps.pageSize);
					 if(emps.list.length==0){
						 $("#curPage").html(0); 
					 }else{
						 $("#curPage").html(page); 
					 }
					 
				}
			});
		}
		fenye(1, " ");//默认显示第一页

		$(".fen a").click( function() {
			//alert("12");
			var curPage = $("#curPage").html();
			var countPage = $("#countPage").html();
			var pageFtn = $(this).html();
			if (pageFtn == "首页") {
				curPage = 1;
			}
			if (pageFtn == "上一页") {
				curPage = parseInt(curPage) - 1;
				if (curPage < 1) {
					curPage = 1;
				}
			}
			if (pageFtn == "下一页") {

				curPage = parseInt(curPage) + 1;
				if (curPage > countPage) {
					curPage = countPage;
				}
			}
			if (pageFtn == "末页") {

				curPage = countPage;
			}
			$("#curPage").html(curPage);
			$("#table tr:gt(0)").remove();
			var hidden = $("#hidden").val();//取隐藏字段中的值
			fenye(curPage, hidden);//这里的值必须重新获取输入框中的值
		});
		
		//查询
		$("#chabut").click(function(){
			 var name=$("#name").val();
			 $("#hidden").val(name);//把text文本框中的值放在隐藏字段中
			 var hidden=$("#hidden").val();
			 $("#table tr:gt(0)").remove();
			 fenye(1,hidden);
			 
		});
		
		
		//删除
		function delete1(id){
				$.ajax({
					   type: "POST",
					   url: "../../delectEnterprise.do",
					   data: {"id":id},
					   success: function(msg){
						   $("#table tr:gt(0)").remove();
						   $("#"+id).remove();
						  var curPage= $("#curPage").html();
						 fenye(curPage," ");
						 if( $("#curPage").html()==0){
							fenye(curPage-1," ");
						 }
					   }
					});
				};
	</script>

</body>
</html>